home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / imc9101.zip / MOUSE1.C < prev    next >
C/C++ Source or Header  |  1990-12-22  |  2KB  |  83 lines

  1. /****************************************************************
  2. *   MOUSE1.C - demonstrate mouse functions 0, 1, 2, & 3         *
  3. *   To compile: cl mouse1.c /link graphics                      *
  4. ****************************************************************/
  5.  
  6. #include <dos.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <conio.h>
  10. #include <graph.h>
  11.  
  12. void main(void)
  13.     {
  14.     int right, left, center, row, col;
  15.     union REGS in_regs, out_regs;
  16.  
  17.     /* Initialize the screen */
  18.     _setvideomode(_TEXTC80);
  19.     _clearscreen(_GCLEARSCREEN);
  20.  
  21.     /* Initialize the mouse */
  22.     in_regs.x.ax = 0;
  23.     int86(0x33, &in_regs, &out_regs);
  24.     if (!out_regs.x.ax)
  25.         {
  26.         printf("Mouse could not be initialized.\n");
  27.         exit(1);
  28.         }
  29.     printf("Mouse initialized.\n");
  30.  
  31.     /* Show the mouse cursor */
  32.     in_regs.x.ax = 1;
  33.     int86(0x33, &in_regs, &out_regs);
  34.  
  35.     /* Hide the mouse cursor */
  36.     printf("Press any key to hide the mouse cursor.\n");
  37.     getch();
  38.     in_regs.x.ax = 2;
  39.     int86(0x33, &in_regs, &out_regs);
  40.  
  41.     /* Redisplay the mouse cursor */
  42.     printf("Press any key to show the mouse cursor again.\n");
  43.     getch();
  44.     in_regs.x.ax = 1;
  45.     int86(0x33, &in_regs, &out_regs);
  46.  
  47.     /* Monitor the button states & position */
  48.     while (1==1)        /* DO FOREVER... */
  49.         {
  50.         /* Get mouse information */
  51.         in_regs.x.ax = 3;
  52.         int86(0x33, &in_regs, &out_regs);
  53.  
  54.         /* Convert to more useful form */
  55.         left   = !!(out_regs.x.bx & 0x01);
  56.         right  = !!(out_regs.x.bx & 0x02);
  57.         center = !!(out_regs.x.bx & 0x04);
  58.         row = out_regs.x.dx / 8 + 1;
  59.         col = out_regs.x.cx / 8 + 1;
  60.  
  61.         /* Print current mouse information */
  62.         _settextposition(10,1);
  63.         printf("Right button is %s.  \n",
  64.                 right ? "down" : "up");
  65.         printf("Left button is %s.  \n",
  66.                 left ? "down" : "up");
  67.         printf("Center button is %s.  \n",
  68.                 center ? "down" : "up");
  69.         printf("Cursor row: %d, cursor column: %d.  \n",
  70.                        row,               col);
  71.  
  72.         /* Quit the loop when user presses '*' */
  73.         if (kbhit())
  74.             if (getch()=='*')
  75.                 break;
  76.         }
  77.  
  78.     /* Turn off the cursor before we quit */
  79.     in_regs.x.ax = 2;
  80.     int86(0x33, &in_regs, &out_regs);
  81.     }
  82.  
  83.